package repositories;

import spotify.ISpotifyGateway;
import webservice.Track;
import org.xml.sax.SAXException;
import spotify.SpotifyGateway;
import spotify.XMLParser;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Wrflohil
 * Date: 13-6-13
 * Time: 9:39
 */
public class TrackRepository implements ITrackRepository {
    private ISpotifyGateway spotifyGateway;
    private XMLParser xmlParser;

    public TrackRepository(ISpotifyGateway spotifyGateway) {
        this.spotifyGateway = spotifyGateway;
        xmlParser = XMLParser.getInstance();
    }

    public List<Track> getTrackList(String searchValue) {
        List<Track> tracks = new ArrayList<Track>();
        try {
            return xmlParser.parse(spotifyGateway.doSearch(searchValue));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }
        return tracks;
    }
}
